# Maintainer: Mario Emmenlauer <memmenlauer@biodataanalysis.de>

_realname=grpc
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_pkgver=0_13_1
pkgver=${_pkgver//_/.}
pkgrel=1
pkgdesc="gRPC - Google's high performance, open source, general RPC framework (mingw-w64)"
arch=('any')
url='http://www.grpc.io/'
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-protobuf")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake" "automake" "autoconf")
options=('staticlibs' 'strip')
source=(${_realname}-release-${_pkgver}.tar.gz::https://github.com/google/grpc/archive/release-${_pkgver}.tar.gz
        https://github.com/nanopb/nanopb/archive/nanopb-0.3.6.tar.gz
	googletest-release-1.7.0.tar.gz::https://github.com/google/googletest/archive/release-1.7.0.tar.gz
        0001-grpc-mingw64.patch)
sha256sums=('74256f85c5c7f42447af8d83fe02fab634cea5497796a398875fddfa91f0aa64'
            '3786aa7fd4e15cfda995a881172f6096dc07c6f5320399b82e824ddf1cc3ac32'
	    'f73a6546fdf9fce9ff93a5015e0333a8af3062a152a9ad6bcb772c96687016cc'
            'ac967493fa0425bf6643888b23567df970a32470b6b1cb18a3e9321a8d4ba7f7')

prepare() {
  cd "${srcdir}/${_realname}-release-${_pkgver}"

  rmdir ./third_party/nanopb
  mv ../nanopb-nanopb-0.3.6 ./third_party/nanopb
  rmdir ./third_party/googletest
  mv ../googletest-release-1.7.0 ./third_party/googletest

  patch -p1 -i ${srcdir}/0001-grpc-mingw64.patch
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -rf "${_realname}-release-${_pkgver}" "build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  CPPFLAGS+=" -D_WIN32_WINNT=0x0601"

  make run_dep_checks
  make STRIP="strip --strip-unneeded" static plugins
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  #make check
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make STRIP="strip --strip-unneeded" prefix="${pkgdir}/${MINGW_PREFIX}" install-headers install-static install-plugins
  install -Dm644 ${srcdir}/${_realname}-release-${_pkgver}/LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE
}
